package com.example.lianjiaproject.controller;

import com.example.lianjiaproject.dao.SpiderDao;
import com.example.lianjiaproject.pojo.Floor_type;
import com.example.lianjiaproject.pojo.Name_value;
import com.example.lianjiaproject.pojo.Price;
import com.example.lianjiaproject.pojo.Subway_type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/SpiderProject")
public class ProjectController {
    @Autowired
    private SpiderDao spiderDao;

    @PostMapping("/AVG_price")
    public List AVG_price(@RequestBody Price price){
        List<Name_value> depts = spiderDao.AVGList(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/House_count")
    public List House_count(@RequestBody Price price){
        List<Name_value> depts = spiderDao.CountList(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/orientation_Count")
    public List orientation_Count(@RequestBody Price price){
        List<Name_value> depts = spiderDao.orientation_Count(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/Level_Count")
    public List Level_Count(@RequestBody Price price){
        List<Name_value> depts = spiderDao.Level_Count(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/apartment_layout_Count")
    public List apartment_layout_Count(@RequestBody Price price){
        List<Name_value> depts = spiderDao.apartment_layout_Count(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/Subway_Count")
    public List Subway_Count(@RequestBody Price price){
        List<Name_value> depts = spiderDao.Subway_Count(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/Avg_Area")
    public List Avg_Area(@RequestBody Price price){
        List<Name_value> depts = spiderDao.Avg_Area(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/Area_Level_Count")
    public List Area_Level_Count(@RequestBody Price price){
        List<Name_value> depts = spiderDao.Area_Level_Count(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/Floor_type")
    public List Floor_type(@RequestBody Price price){
        List<Floor_type> depts = spiderDao.Floor_type(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/Subway_type")
    public List Subway_type(@RequestBody Price price){
        List<Subway_type> depts = spiderDao.Subway_type(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/Floor_price")
    public List Floor_price(@RequestBody Price price){
        List<Floor_type> depts = spiderDao.Floor_price(price.getMin(),price.getMax(),price.getRent(),price.getRegion(),price.getFloor(),price.getLift());
        return depts;
    }

    @PostMapping("/RLT")
    public List RLT(@RequestBody Price price){
        List<List<Name_value>> depts = new ArrayList<>();
        String[] region={"东丽区","北辰区","南开区","和平区","宁河区","宝坻区","武清区","河东区","河北区","河西区","津南区","滨海新区","红桥区","蓟州区","西青区","静海区"};
        for(int i=0;i<16;i++){
            depts.add(spiderDao.Level_Count(price.getMin(),price.getMax(),price.getRent(),"='"+region[i]+"'",price.getFloor(),price.getLift()));
        }
        return depts;
    }

}
